package com.bachelor.community.mapper;

import com.bachelor.community.model.entity.User;
import com.bachelor.community.model.vo.UserVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Select("select distinct class_number from user where class_number is not null")
    List<String> listClassNumbers();

    @Select("select answer.answerer as id, user.username as username, sum(vote_count) as like_count from answer, user " +
            "where user.id=answer.answerer group by answer.answerer, user.username with rollup having username is not null " +
            "order by like_count desc")
    IPage<UserVO> listUsersOrderByLikeCount(IPage<UserVO> page);
}
